import {reqSeekFamily,getAreas,getCity} from '@/api/seek'
// seekfamily模块的小仓库
// state：仓库存储数据的地方
const state = {
    provinceList:[],
    cityList:[]
};
// mutations：修改state的唯一手段
const mutations = {
    PROVINCELIST(state,provinceList) {
        state.provinceList = provinceList;
    },
    SELECTEDPROVINCE(state,cityList) {
        state.cityList = cityList;
    }
};
// actions：处理actions，可以书写自己的业务逻辑，处理异步任务
const actions = {
    // 获取所有省份的数据
    async provinceList({commit}) {
        let result =  await getAreas();
        console.log(result.data);
        if (result.code == 200) {
            commit('PROVINCELIST',result.data.provinceList);
        }
    },
    // 获取二级联动城市的数据
    async selectedProvince({commit},province) {
        let result = await getCity(province);
        console.log(result.data);
        if (result.code == 200) {
            commit('SELECTEDPROVINCE',result.data.cityList);
        }
    },
    // 获取seekFamily的数据
    async seekFamily({commit},userData){
        let result = await reqSeekFamily(userData);
        console.log(result);
    }
};
// getters：理解为计算属性，用于简化仓库数据，让组件获取仓库的数据更加方便
const getters = {};
export default {
    // Vuex的配置对象，key值不能瞎写
    state,
    mutations,
    actions,
    getters
}